package com.example.juc.controller;

import java.util.concurrent.*;

/**
 * @author jl
 * @since 2021/9/25 19:35
 */
public class CompletableFutureAPIDemo {
    static ThreadPoolExecutor executor = new ThreadPoolExecutor(5, 20, 1, TimeUnit.MINUTES,
            new LinkedBlockingQueue<>(50), Executors.defaultThreadFactory(), new ThreadPoolExecutor.CallerRunsPolicy());

    public static void main(String[] args) {
        Integer join = CompletableFuture.supplyAsync(() -> {
            return 10;
        }).thenCombine(CompletableFuture.supplyAsync(() -> {
            return 20;
        }), (r1, r2) -> {
            return r1 + r2;
        }).join();
        System.out.println(join);  // 30
    }

}
